﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace RepairTracker
{


    public static class Entity
    {
        public static string connectionString =
            //ConfigurationManager.ConnectionStrings["ConnectionString_Local_SBK_Test"].ConnectionString;
            ConfigurationManager.ConnectionStrings["ConnectionString_Local_SBK"].ConnectionString;

        public static List<ProductSet> GetAllProducts()
        {

            List<ProductSet> ret = new List<ProductSet>();

            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetAllProducts", conn);
            SqlDataReader reader;

            cmd.CommandType = CommandType.StoredProcedure;
            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ProductSet p = new ProductSet();
                    p.Id = (int)reader["id"];
                    p.SerialNo = reader["SerialNO"].ToString();
                    p.PsamNo = reader["PsamNO"].ToString();
                    p.Version = reader["Version"].ToString();
                    p.DeviceName = reader["DeviceName"].ToString();
                    p.DistrictName = reader["DistrictName"].ToString();
                    p.OwnerName = reader["DisplayName"].ToString();
                    p.DeviceId = (int)reader["DeviceId"];
                    p.DistrictId = (int)reader["DistrictId"];
                    p.OwnerId = (int)reader["OwnerId"];
                    p.Counts = (int)reader["Counts"];
                    ret.Add(p);
                }
            }

            return ret;
        }

        public static bool UpdateProduct(int id, int deviceId, int ownerId, string serialNO, string psamNO, string version)
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("update products set DeviceId=@DeviceId,OwnerId=@OwnerId,SerialNO=@SerialNO,PsamNO=@PsamNO,Version=@Version where Id=@Id", conn);
            //SqlDataReader reader;
            cmd.Parameters.AddWithValue("@DeviceId", deviceId);
            cmd.Parameters.AddWithValue("@OwnerId", ownerId);
            cmd.Parameters.AddWithValue("@SerialNO", serialNO.Trim());
            cmd.Parameters.AddWithValue("@PsamNO", psamNO.Trim());
            cmd.Parameters.AddWithValue("@Version", version.Trim());
            cmd.Parameters.AddWithValue("@Id", id);
            using (conn)
            {
                conn.Open();
                try
                {
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }

                }
                catch
                {

                }
            }

            return false;
        }

        public static List<ProductSet> GetProductsByOwnerId(int statusId, int deviceId, int ownerId)
        {

            List<ProductSet> ret = new List<ProductSet>();

            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetProductsByOwner", conn);
            SqlDataReader reader;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@StatusId", statusId);
            cmd.Parameters.AddWithValue("@DeviceId", deviceId);
            cmd.Parameters.AddWithValue("@OwnerId", ownerId);
            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ProductSet p = new ProductSet();
                    p.Id = (int)reader["id"];
                    p.SerialNo = reader["SerialNO"].ToString();
                    p.PsamNo = reader["PsamNO"].ToString();
                    p.Version = reader["Version"].ToString();
                    p.DeviceName = reader["DeviceName"].ToString();
                    p.DistrictName = reader["DistrictName"].ToString();
                    p.OwnerName = reader["DisplayName"].ToString();
                    p.Counts = (int)reader["Counts"];
                    p.DeviceId = (int)reader["DeviceId"];
                    p.DistrictId = (int)reader["DistrictId"];
                    p.OwnerId = (int)reader["OwnerId"];
                    ret.Add(p);
                }
            }

            return ret;
        }

        public static List<ProductSet> GetProductBySerialNO(int statusId, string serialNO)
        {
            if (statusId==0)
            {
                return null;
            }

            if (serialNO==null)
            {
                return null;
            }

            List<ProductSet> ret = new List<ProductSet>();

            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetProductBySerialNO", conn);
            SqlDataReader reader;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@StatusId", statusId);
            cmd.Parameters.AddWithValue("@SerialNO", serialNO.Trim());
            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ProductSet p = new ProductSet();
                    p.Id = (int)reader["id"];
                    p.SerialNo = reader["SerialNO"].ToString();
                    p.PsamNo = reader["PsamNO"].ToString();
                    p.Version = reader["Version"].ToString();
                    p.DeviceName = reader["DeviceName"].ToString();
                    p.DeviceId = (int)reader["DeviceId"];
                    p.DistrictName = reader["DistrictName"].ToString();
                    p.OwnerName = reader["DisplayName"].ToString();
                    p.Counts = (int)reader["Counts"];
                    ret.Add(p);
                }
            }

            return ret;
        }

        public static List<District> GetAllDistricts()
        {
            List<District> ret = new List<District>();
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetAllDistricts", conn);
            SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;

            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    District d = new District();
                    d.Id = (int)reader["id"];
                    d.DistrictName = reader["DistrictName"].ToString();
                    ret.Add(d);
                }
            }
            return ret;
        }

        public static List<Fault> GetFaultsByDevice(int deviceId)
        {
            List<Fault> ret = new List<Fault>();
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetFaultsByDevice", conn);
            SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@DeviceId", deviceId);

            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Fault f = new Fault();
                    f.Id = (int)reader["id"];
                    f.FaultName = reader["FaultName"].ToString();
                    f.FaultCode = reader["FaultCode"].ToString();
                    f.FaultDeviceId = (int)reader["FaultDevice"];
                    ret.Add(f);
                }
            }
            return ret;
        }


        /// <summary>
        /// out of date
        /// </summary>
        /// <returns></returns>
        public static List<Fault> GetAllFaults()
        {
            List<Fault> ret = new List<Fault>();
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetAllFaults", conn);
            SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;

            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Fault f = new Fault();
                    f.Id = (int)reader["id"];
                    f.FaultName = reader["FaultName"].ToString();
                    f.FaultCode = reader["FaultCode"].ToString();
                    ret.Add(f);
                }
            }
            return ret;
        }

        public static List<Device> GetAllDevices()
        {
            List<Device> ret = new List<Device>();
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetAllDevices", conn);
            SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;

            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Device d = new Device();
                    d.Id = (int)reader["id"];
                    d.DeviceName = reader["DeviceName"].ToString();
                    ret.Add(d);
                }
            }
            return ret;
        }

        public static List<Owner> GetOwnersByDistrictId(int districtId)
        {
            List<Owner> ret = new List<Owner>();
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("GetOwnersByDistrictId", conn);
            SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@DistrictId", districtId);
            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Owner o = new Owner();
                    o.Id = (int)reader["id"];
                    o.DisplayName = reader["DisplayName"].ToString();
                    ret.Add(o);
                }
            }
            return ret;
        }

        public static int ProductInsertAndInput(int deviceId, int ownerId, string serialNO, string psamNO, string version, int requestFaultId)
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("InsertAndInputProduct", conn);
            //SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@DeviceId", deviceId);
            cmd.Parameters.AddWithValue("@OwnerId", ownerId);
            cmd.Parameters.AddWithValue("@SerialNO", serialNO.Trim());
            cmd.Parameters.AddWithValue("@PsamNO", psamNO.Trim());
            cmd.Parameters.AddWithValue("@Version", version.Trim());
            cmd.Parameters.AddWithValue("@RequestFaultId", requestFaultId);

            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.BigInt);
            cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;

            using (conn)
            {
                conn.Open();
                try
                {
                    cmd.ExecuteNonQuery();

                }
                catch
                {
                }
            }

            return (int)cmd.Parameters["@RETURN_VALUE"].Value;

        }

        public static int ProductInput(int productId, int requestFaultId)
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("ProductInput", conn);
            //SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ProductId", productId);
            cmd.Parameters.AddWithValue("@RequestFaultId", requestFaultId);
            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.BigInt);
            cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;

            using (conn)
            {
                conn.Open();
                cmd.ExecuteNonQuery();

            }

            return (int)cmd.Parameters["@RETURN_VALUE"].Value;
        }

        public static int ProductRepaired(int productId, int realFaultId, string faultDetails, string repairMethod, string repairGear)
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("ProductRepaired", conn);
            //SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ProductId", productId);
            cmd.Parameters.AddWithValue("@RealFaultId", realFaultId);
            cmd.Parameters.AddWithValue("@RepairMethod", repairMethod);
            cmd.Parameters.AddWithValue("@RepairGear", repairGear);
            cmd.Parameters.AddWithValue("@FaultDetails", faultDetails);
            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.BigInt);
            cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;

            using (conn)
            {
                conn.Open();
                cmd.ExecuteNonQuery();

            }

            return (int)cmd.Parameters["@RETURN_VALUE"].Value;
        }

        public static int ProductOutput(int productId)
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("ProductOutput", conn);
            //SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ProductId", productId);
            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.BigInt);
            cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;

            using (conn)
            {
                conn.Open();
                cmd.ExecuteNonQuery();

            }

            return (int)cmd.Parameters["@RETURN_VALUE"].Value;
        }

        //public static List<RecordSet> DirectSearchRecords(DateTime inDateStart, DateTime inDateEnd)
        //{
        //    return DirectSearchRecords(0,0,0, inDateStart, inDateEnd,);
        //}

        //public static List<RecordSet> DirectSearchRecords(int ownerId, int realFaultId, string serialNO, DateTime inDateStart, DateTime inDateEnd)
        //{
        //    ///Path
        //    ///
        //    /////////
        //    inDateEnd=inDateEnd.AddDays(1);
        //    //////

        //    StringBuilder cmdStr = new StringBuilder();
        //    cmdStr.AppendLine("select");
        //    cmdStr.AppendLine("di.DistrictName,");
        //    cmdStr.AppendLine("o.DisplayName,");
        //    cmdStr.AppendLine("d.DeviceName,");
        //    cmdStr.AppendLine("p.SerialNO,");
        //    cmdStr.AppendLine("p.PsamNO,");
        //    cmdStr.AppendLine("p.Version,");
        //    cmdStr.AppendLine("req.FaultCode+req.FaultName RequestFaultName,");
        //    cmdStr.AppendLine("rel.FaultCode+rel.FaultName RealFaultName,");
        //    cmdStr.AppendLine("r.InDate,");
        //    cmdStr.AppendLine("r.OutDate,");
        //    cmdStr.AppendLine("r.RepairMethod");
        //    cmdStr.AppendLine("from Records r");
        //    cmdStr.AppendLine("left outer join Products p on p.Id=r.ProductId");
        //    cmdStr.AppendLine("join Owners o on o.Id=p.OwnerId");
        //    cmdStr.AppendLine("join Districts di on di.Id=o.DistrictId");
        //    cmdStr.AppendLine("join Devices d on d.Id=p.DeviceId");
        //    cmdStr.AppendLine("join Faults req on req.Id=r.RequestFaultID");
        //    cmdStr.AppendLine("join Faults rel on rel.Id=r.RealFaultID");
        //    //cmdStr.AppendLine("where");

        //    bool prefixAnd = false;
        //    bool prefixWhere = true;
        //    SqlConnection conn = new SqlConnection(Entity.connectionString);
        //    SqlCommand cmd = new SqlCommand();
        //    cmd.Connection = conn;


        //    if (ownerId != 0)
        //    {

        //        cmdStr.AppendLine((prefixWhere ? " where " : "") + "o.Id=@OwnerId" + (prefixAnd ? " and " : ""));
        //        prefixAnd = true;
        //        prefixWhere = false;
        //        cmd.Parameters.AddWithValue("@OwnerId", ownerId);
        //    }

        //    if (realFaultId != 0)
        //    {

        //        cmdStr.AppendLine((prefixWhere ? " where " : "") + (prefixAnd ? " and " : "") + "rel.Id=@RealFaultId");
        //        prefixAnd = true;
        //        prefixWhere = false;
        //        cmd.Parameters.AddWithValue("@RealFaultId", realFaultId);
        //    }

        //    cmdStr.AppendLine((prefixWhere ? " where " : "") + (prefixAnd ? " and " : "") + "r.InDate>@InDateStart");
        //    prefixAnd = true;
        //    prefixWhere = false;
        //    cmd.Parameters.AddWithValue("@InDateStart", inDateStart);

        //    cmdStr.AppendLine((prefixWhere ? " where " : "") + (prefixAnd ? " and " : "") + "r.InDate<=@InDateEnd");
        //    prefixAnd = true;
        //    prefixWhere = false;
        //    cmd.Parameters.AddWithValue("@InDateEnd", inDateEnd);



        //    cmdStr.AppendLine("order by r.InDate");
        //    cmd.CommandText = cmdStr.ToString();
        //    SqlDataReader reader;

        //    List<RecordSet> ret = new List<RecordSet>();

        //    using (conn)
        //    {
        //        conn.Open();
        //        reader = cmd.ExecuteReader();
        //        while (reader.Read())
        //        {
        //            RecordSet r = new RecordSet();
        //            r.DistrictName = reader["DistrictName"].ToString();
        //            r.OwnerName = reader["DisplayName"].ToString();
        //            r.DeviceName = reader["DeviceName"].ToString();
        //            r.SerialNo = reader["SerialNO"].ToString();
        //            r.PsamNo = reader["PsamNO"].ToString();
        //            r.Version = reader["Version"].ToString();
        //            r.RequestFaultName = reader["RequestFaultName"].ToString();
        //            r.RealFaultName = reader["RealFaultName"].ToString();
        //            r.RepairMethod = reader["RepairMethod"].ToString();
        //            try
        //            {

        //                if (reader["InDate"] == null)
        //                {
        //                    r.InDate = "";
        //                }
        //                else
        //                {
        //                    r.InDate = reader["InDate"].ToString();
        //                }
        //                if (reader["OutDate"] == null)
        //                {
        //                    r.OutDate = "";
        //                }
        //                else
        //                {
        //                    r.OutDate = reader["OutDate"].ToString();
        //                }

        //            }
        //            catch (SqlException ex)
        //            {


        //            }

        //            ret.Add(r);

        //        }

        //    }
        //    return ret;

        //}


        public static List<RecordSet> DirectSearchRecords(
            int distictId, int ownerId, int deviceId, int realFaultId,
            DateTime inDateStart, DateTime inDateEnd, DateTime outDateStart ,DateTime outDateEnd,
            string version) 
        {
            ///Patch
            ///
            /////////
            inDateEnd = inDateEnd.AddDays(1);
            //////

            StringBuilder cmdStr = new StringBuilder();
            StringBuilder paraStr = new StringBuilder();
            cmdStr.AppendLine("select");
            cmdStr.AppendLine("di.DistrictName,");
            cmdStr.AppendLine("o.DisplayName,");
            cmdStr.AppendLine("d.DeviceName,");
            cmdStr.AppendLine("p.SerialNO,");
            cmdStr.AppendLine("p.PsamNO,");
            cmdStr.AppendLine("p.Version,");
            cmdStr.AppendLine("req.FaultCode+req.FaultName RequestFaultName,");
            cmdStr.AppendLine("rel.FaultCode+rel.FaultName RealFaultName,");
            cmdStr.AppendLine("r.InDate,");
            cmdStr.AppendLine("r.OutDate,");
            cmdStr.AppendLine("r.RepairMethod");
            cmdStr.AppendLine("from Records r");
            cmdStr.AppendLine("left outer join Products p on p.Id=r.ProductId");
            cmdStr.AppendLine("join Owners o on o.Id=p.OwnerId");
            cmdStr.AppendLine("join Districts di on di.Id=o.DistrictId");
            cmdStr.AppendLine("join Devices d on d.Id=p.DeviceId");
            cmdStr.AppendLine("join Faults req on req.Id=r.RequestFaultID");
            cmdStr.AppendLine("join Faults rel on rel.Id=r.RealFaultID");
            //cmdStr.AppendLine("where");

            //bool prefixWhere = true;
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            cmdStr.AppendLine("where");
            if (distictId != 0)
            {
                paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
                paraStr.AppendLine("di.Id=@DistrictId");
                cmd.Parameters.AddWithValue("@DistrictId", distictId);

                if (ownerId != 0)
                {
                    paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
                    paraStr.AppendLine("o.Id=@OwnerId");
                    cmd.Parameters.AddWithValue("@OwnerId", ownerId);
                }
            }

            if (deviceId != 0)
            {
                paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
                paraStr.AppendLine("d.Id=@DeviceId");
                cmd.Parameters.AddWithValue("@DeviceId", deviceId);
            }

            if (realFaultId != 0)
            {
                paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
                paraStr.AppendLine("rel.Id=@RealFaultId");
                cmd.Parameters.AddWithValue("@RealFaultId", realFaultId);
            }

            //入库时间段
            paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
            paraStr.AppendLine("r.InDate>@InDateStart");
            cmd.Parameters.AddWithValue("@InDateStart", inDateStart);

            paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
            paraStr.AppendLine("r.InDate<=@InDateEnd");
            cmd.Parameters.AddWithValue("@InDateEnd", inDateEnd);

            //出库时间段
            /*
            paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
            paraStr.AppendLine("r.OutDate>@OutDateStart");
            cmd.Parameters.AddWithValue("@OutDateStart", outDateStart);

            paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
            paraStr.AppendLine("r.OutDate<=@OutDateEnd");
            cmd.Parameters.AddWithValue("@OutDateEnd", outDateEnd);
            */


            if (!string.IsNullOrEmpty(version))
            {
                paraStr.AppendLine((paraStr.Length == 0 ? "" : " and"));
                paraStr.AppendLine("p.Version = @Version");
                cmd.Parameters.AddWithValue("@Version", version.ToUpper());
            }


            paraStr.AppendLine("order by r.InDate");
            cmd.CommandText = cmdStr.ToString()+paraStr.ToString();
            SqlDataReader reader;

            List<RecordSet> ret = new List<RecordSet>();

            using (conn)
            {
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    RecordSet r = new RecordSet();
                    r.DistrictName = reader["DistrictName"].ToString();
                    r.OwnerName = reader["DisplayName"].ToString();
                    r.DeviceName = reader["DeviceName"].ToString();
                    r.SerialNo = reader["SerialNO"].ToString();
                    r.PsamNo = reader["PsamNO"].ToString();
                    r.Version = reader["Version"].ToString();
                    r.RequestFaultName = reader["RequestFaultName"].ToString();
                    r.RealFaultName = reader["RealFaultName"].ToString();
                    r.RepairMethod = reader["RepairMethod"].ToString();
                    try
                    {

                        if (reader["InDate"] == null)
                        {
                            r.InDate = "";
                        }
                        else
                        {
                            r.InDate = reader["InDate"].ToString();
                        }
                        if (reader["OutDate"] == null)
                        {
                            r.OutDate = "";
                        }
                        else
                        {
                            r.OutDate = reader["OutDate"].ToString();
                        }

                    }
                    catch (SqlException ex)
                    {


                    }

                    ret.Add(r);

                }

            }
            return ret;
        }

        /// <summary>
        /// return user premission /zero is not authenticated
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static int UserAuthenticate(string userName, string password) 
        {
            SqlConnection conn = new SqlConnection(Entity.connectionString);
            SqlCommand cmd = new SqlCommand("UserAuthenticate", conn);
            //SqlDataReader reader;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Username", userName);
            cmd.Parameters.AddWithValue("@Password", password);
            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.BigInt);
            cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;

            using (conn)
            {
                conn.Open();
                cmd.ExecuteNonQuery();

            }

            return (int)cmd.Parameters["@RETURN_VALUE"].Value;
        }
    }

    
    public static class UserInfo 
    {
        public static string UserName { get; set; }
        public static int Permission { get; set; }
    } 
    
    public class Crew
    {
        int Id { get; set; }
        string CrewName { get; set; }
        int Premission { get; set; }
        string Password { get; set; }

    }

    public class Device 
    {
        public int Id { get; set; }
        public string DeviceName { get; set; }
    }

    public class District
    {
        public int Id { get; set; }
        public string DistrictName { get; set; }
    }

    public class Fault 
    {
        public int Id { get; set; }
        public string FaultName { get; set; }
        public string FaultCode { get; set; }
        public int FaultDeviceId { get; set; }
    }

    public class Owner 
    {
        public int Id { get; set; }
        public int DistrictId { get; set; }
        public string DisplayName { get; set; }
    }

    //public class Status
    //{
    //    int Id { get; set; }
    //    string Status { get; set; }
    //}


    public class ProductSet 
    {
        public int Id { get; set; }
        public int DeviceId { get; set; }
        public string DeviceName { get; set; }
        public int DistrictId { get; set; }
        public string DistrictName { get; set; }
        public int OwnerId { get; set; }
        public string OwnerName { get; set; }
        public string SerialNo { get; set; }
        public string PsamNo { get; set; }
        public string Version { get; set; }
        public int Counts { get; set; }
    }

    public class RecordSet 
    {
        public string DistrictName { get; set; }
        public string OwnerName { get; set; }
        public string DeviceName { get; set; }
        public string SerialNo { get; set; }
        public string PsamNo { get; set; }
        public string Version { get; set; }
        public string RequestFaultName { get; set; }
        public string RealFaultName { get; set; }
        public string InDate { get; set; }
        public string OutDate { get; set; }
        public string RepairMethod { get; set; }
    }
}